package com.qf.controller;

import com.qf.pojo.Spit;
import com.qf.service.SpitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 千锋健哥
 */
@RestController
@RequestMapping("/spit")
public class SpitController {

    @Autowired
    private SpitService spitService;

    /**
     * 添加吐槽
     * @param spit
     * @return
     */
    @PostMapping("/insert")
    public String insert(@RequestBody Spit spit) {
        spitService.insert(spit);
        return "success";
    }

    /**
     * 修改
     * @param spit
     * @return
     */
    @PutMapping("/update")
    public String update(@RequestBody Spit spit) {
        spitService.update(spit);
        return "success";
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public String deleteById(@PathVariable(value = "id") String id) {
        spitService.deleteById(id);
        return "success";
    }

    /**
     * 根据主键查询
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public Spit findOne(@PathVariable(value = "id") String id) {
        Spit one = spitService.findOne(id);
        return one;
    }

    /**
     * 根据条件查询
     * @param spit
     * @return
     */
    @GetMapping("/findList")
    public List<Spit> findList(@RequestBody Spit spit) {
        List<Spit> list = spitService.findList(spit);
        return list;
    }
}
